package Game;

public class Position implements Cloneable{
    /*
    * Position存储的是逻辑地址
    * 方便操作
    * */
    int LogicX ;
    int LogicY ;

    public void setX(int logicX) {
        LogicX = logicX;
    }

    public void setY(int logicY) {
        LogicY = logicY;
    }

    public int getX() {
        return LogicX;
    }

    public int getY() {
        return LogicY;
    }
    public void move(@org.jetbrains.annotations.NotNull ActionType dir){
        switch (dir){
            /*
            * 为了符合一般游戏的设计
            * y小在上，y大在下
            * 此处将UP与DOWN操作反转
             */
            case UP     ->  LogicY--;
            case DOWN   ->  LogicY++;
            case LEFT   ->  LogicX -- ;
            case RIGHT  ->  LogicX ++;
            case ROTATE -> rotate();
            case ROTATE_BACK -> rotate_back();
        }
    }

    public void rotate(){
        /*
        * 基于自己的逻辑地址
        * 顺时针旋转90°
        * */
        int x =   this.LogicY;
        int y = - this.LogicX;
        this.LogicX = x ;
        this.LogicY = y ;
    }

    public void rotate_back(){
        int x = -this.LogicY ;
        int y = this.LogicX;

        this.LogicX = x ;
        this.LogicY = y ;
    }
    Position(int x , int y){
        this.LogicX = x ;
        this.LogicY = y ;
    }
    Position(){
        this.LogicX = 0 ;
        this.LogicY = 0 ;
    }

    @Override
    public Position clone() throws CloneNotSupportedException {
        return new Position(this.getX() , this.getY());
    }
}
